package com.pet.mapper;

import com.github.pagehelper.Page;
import com.pet.dto.web.UserLoginDTO;
import com.pet.entity.Employee;
import com.pet.entity.UserInformation;
import com.pet.pageDto.UserInfoPageDTO;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.time.LocalDateTime;

@Mapper
public interface UserInformationMapper {

    /**
     * 根据用户名查询员工
     * @param username
     * @return
     */
    @Select("select * from pet_manage_system.user_information where username = #{username}")
    Employee getByUsername(String username);

    @Select("select name from user_information where id = #{createUser}")
    String selectName(Integer createUser);

    /**
     *上传/修改主页背景
     * @param imgUrl
     */
    @Update("update pet_manage_system.user_information set background = #{imgUrl} where id = #{id}")
    void updateHomepageBackground(String imgUrl, Long id);

    /**
     * 查询用户信息
     * @param currentId
     * @return
     */
    @Select("select * from user_information where id = #{currentId}")
    UserInformation selectUserInformation(Long currentId);

    /**
     * 修改用户信息
     * @param e
     */
    void updateUserInfo(UserInformation e);


    @Insert("INSERT INTO user_information " +
            "(username, password, name, phone, wechat, qq_account, address, gender, self_introduction, " +
            "profile_photo,create_time) " +
            "values " +
            "(#{username},#{password},#{name},#{phone},#{wechat},#{qqAccount},#{address}," +
            "#{gender},#{selfIntroduction},#{profilePhoto},#{createTime})")
    void insertUserInformation(UserInformation userInformation);

    /**
     * 根据id查询头像
     * @param createUser
     * @return
     */
    @Select("select profile_photo from user_information where id = #{createUser}")
    String selectProfilePhotoById(Integer createUser);

    /**
     * 修改最后登录时间
     * @param now
     * @param id
     */
    @Update("update user_information set last_login = #{now} where id = #{id}")
    void updateLastLoginTime(LocalDateTime now, Long id);

    /**
     * 修改密码
     * @param userLoginDTO
     * @param currentId
     */
    @Update("update user_information set password = #{password} where id = #{currentId}")
    void updatePassword(String password, Long currentId);

    /**
     * 查询所有用户信息
     * @param pageDTO
     * @return
     */
    Page<UserInformation> pageUserInformationAll(UserInfoPageDTO pageDTO);
}
